<?php if (!defined('THINK_PATH')) exit();?>
<script type="text/javascript" src="{MODULE_ROOT}web/resource/js/jquery.dialog.js"></script>
<link type="text/css" href="{MODULE_ROOT}web/resource/css/jquery.dialog.css" rel="stylesheet">
<ul class="nav nav-tabs">
    <li><a href="javascript:history.go(-1);">返回</a></li>
    <li {if $operation == 'post'}class="active"{/if}><a href="{php echo $this->createWebUrl('activity', array('op' => 'post'));}">添加主题</a></li>
    <li {if $operation == 'display'}class="active"{/if}><a href="{php echo $this->createWebUrl('activity', array('op' => 'display'));}">管理主题</a></li>
</ul>
<link href="../addons/wmb_goshare/template/css/lhgcalendar.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../addons/wmb_goshare/template/js/lhgcore.min.js"></script>
<script type="text/javascript" src="../addons/wmb_goshare/template/js/lhgcalendar.min.js"></script>

<style>
    .activity_list{overflow:hidden; padding-top:15px;}
    .activity_list li{border:1px #DDD solid; width:320px; float:left; margin-left:15px; margin-bottom:10px;}
    .activity_list li .activity_pic{display:block; width:320px; height:160px; overflow:hidden;}
    .activity_list li .activity_pic img{width:320px;}
    .activity_list li .activity_main{padding:10px; overflow:hidden;}
    .activity_list li .activity_main .activity_title{font-size:16px; height:20px; width:217px; overflow:hidden;}
    .activity_list li .activity_main .pull-left{color:#999;}
</style>
{if $operation == 'post'}
<div class="main">
    <form action="" method="post" onsubmit="return check(this)" class="form-horizontal form" enctype="multipart/form-data">
        <input type="hidden" name="activityId" value="<?php echo ($activity['id']); ?>" />
        <div class="panel panel-default">
            <div class="panel-heading">
                <div class="panel-title">主题编辑</div>
            </div>
            <div class="panel-body">
                <div class="form-group">
                    <label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label">活动地址</label>
                    <div class="col-sm-8 col-xs-12">
                        <input type="text" class="form-control" value="<?php echo ($project_link); ?>" disabled="disabled">
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style='color:red'>*</span> 活动主题名称</label>
                    <div class="col-sm-9 col-xs-12">
                        <input type="text" name="title" class="form-control" value="<?php echo ($activity['title']); ?>" placeholder="活动主题名称" />
                        <div class="help-block"></div>
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style='color:red'>*</span> 主题图片</label>
                    <div class="col-sm-9 col-xs-12">
                        <input type="hidden" name="thumb_old" value="<?php echo ($activity['thumb']); ?>">
                        {php echo tpl_form_field_image('thumb', $activity['thumb']);}
                        <div class="help-block">*建议图片像素：640*400</div>
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">活动人数</label>
                    <div class="col-md-4">
                        <div class="input-group">
                            <input type="text" name="personnum" class="form-control" value="<?php echo ($activity['personnum']); ?>" placeholder="不填写无限制" />
                            <span class="input-group-addon">人</span>
                        </div>
                        <!--<input type="checkbox" name="scratch[only_others]" id="only_others" value="1"  />仅送给未中奖的用户-->
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style='color:red'>*</span> 活动时间</label>
                    <div class="col-sm-9 col-xs-12">
                        {php echo tpl_form_field_daterange('activityTime', array('start' =>$activity['starttime'],'end' =>$activity['endtime']), true);}
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style='color:red'>*</span> 主办方名称</label>
                    <div class="col-sm-9 col-xs-12">
                        <input type="text" name="unit" class="form-control" value="<?php echo ($activity['unit']); ?>" placeholder="主办方名称" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">门店位置</label>
                    <div class="col-sm-9 col-xs-12">

                        {php echo tpl_form_field_coordinate('map',array('lng'=>$activity['lng'],'lat'=>$activity['lat']))}

                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style='color:red'>*</span> 活动地点</label>
                    <div class="col-sm-9 col-xs-12">
                        <input type="text" name="address" class="form-control" value="<?php echo ($activity['address']); ?>" placeholder="活动详细地址" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style='color:red'>*</span> 活动介绍</label>
                    <div class="col-sm-9 col-xs-12">
                        {php echo tpl_ueditor('detail', $activity['detail']);}
                    </div>
                </div>
                <div class="form-group" style="display:none">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style='color:red'>*</span> 逾期主题名称</label>
                    <div class="col-sm-9 col-xs-12">
                        <textarea style="height:100px; width:600px;" class="span7 jq_watermark" name="overtitle" cols="70" placeholder="活动已经结束啦，下次早点来哟"><?php echo ($activity['overtitle']); ?></textarea>
                    </div>
                </div>

                <div class="form-group" style="display:none">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style='color:red'>*</span> 奖品组设置</label>
                    <div class="col-sm-9 col-xs-12">
                        <select name="groupid" id="groupid"
                                class="form-control" style="float: left">
                            {loop $groups $group}
                            <option value="<?php echo ($group['id']); ?>" {if $group['id'] == $activity['groupid']} selected = "selected" {/if} ><?php echo ($group['groupname']); ?></option>
                            {/loop}
                        </select>
                        <script>
                            if ("<?php echo ($activity['groupname']" != "") {
                                $("?>";
                            }
                        </script>
                    </div>
                </div>
                <div class="form-group" style="display:none">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style='color:red'>*</span> 兑奖地址</label>
                    <div class="col-sm-9 col-xs-12">
                        <input type="text" name="place" class="form-control" value="<?php echo ($activity['place']); ?>" placeholder="兑奖地址" />
                    </div>
                </div>
                <div class="form-group" style="display:none">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style='color:red'>*</span> 兑奖电话</label>
                    <div class="col-sm-9 col-xs-12">
                        <input type="text" id="tel" name="tel" class="form-control" value="<?php echo ($activity['tel']); ?>" placeholder="兑奖电话" />
                    </div>
                </div>
                <div class="form-group" style="display:none">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style='color:red'>*</span> 广告一区标题</label>
                    <div class="col-sm-9 col-xs-12">
                        <input type="text" name="ad1" class="form-control" value="<?php echo ($activity['ad1']); ?>" placeholder="标题" />
                    </div>
                </div>
                <div class="form-group" style="display:none">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style='color:red'>*</span> 广告一区内容</label>
                    <div class="col-sm-9 col-xs-12">
                        <textarea id='share_txt' style="height:200px; width:600px;" class="span7 jq_watermark" name="ad1content" cols="70" placeholder="广告内容"><?php echo ($activity['ad1content']); ?></textarea>
                    </div>
                </div>
                <div class="form-group" style="display:none">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style='color:red'>*</span> 广告二区标题</label>
                    <div class="col-sm-9 col-xs-12">
                        <input type="text" name="ad2" class="form-control" value="<?php echo ($activity['ad2']); ?>" placeholder="标题" />
                    </div>
                </div>
                <div class="form-group" style="display:none">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style='color:red'>*</span> 广告二区内容</label>
                    <div class="col-sm-9 col-xs-12">
                        <textarea  id='share_txta' style="height:200px; width:600px;" class="span7 jq_watermark" name="ad2content" cols="70" placeholder="广告内容"><?php echo ($activity['ad2content']); ?></textarea>
                    </div>
                </div>
                <div class="form-group" style="display:none">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style='color:red'>*</span> 广告三区标题</label>
                    <div class="col-sm-9 col-xs-12">
                        <input type="text" name="ad3" class="form-control" value="<?php echo ($activity['ad3']); ?>" placeholder="标题" />
                    </div>
                </div>
                <div class="form-group" style="display:none">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style='color:red'>*</span> 广告三区内容</label>
                    <div class="col-sm-9 col-xs-12">
                        <textarea id='share_txtb' style="height:200px; width:600px;" class="span7 jq_watermark" name="ad3content" cols="70" placeholder="广告内容"><?php echo ($activity['ad3content']); ?></textarea>
                    </div>
                </div>
                <div class="form-group" style="display:none">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style='color:red'>*</span> 广告三区图片</label>
                    <div class="col-sm-9 col-xs-12">
                        {php echo tpl_form_field_image('ad3pic', $activity['ad3pic']);}
                        <div class="help-block">*建议图片像素：640*900</div>
                    </div>
                </div>
                <div class="form-group" style="display:none">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style='color:red'>*</span> 页面底部横幅图片</label>
                    <div class="col-sm-9 col-xs-12">
                        {php echo tpl_form_field_image('footpic', $activity['footpic']);}
                        <div class="help-block">*建议图片像素：300*30</div>
                    </div>
                </div>
                <div class="form-group" style="display:none">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style='color:red'>*</span> 底部图片链接地址</label>
                    <div class="col-sm-9 col-xs-12">
                        <input type="text" name="url" class="form-control" value="<?php echo ($activity['url']); ?>" placeholder="http://" />
                    </div>
                </div>
                <div class="form-group" style="display:none">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style='color:red'>*</span> 分享图标</label>
                    <div class="col-sm-9 col-xs-12">
                        {php echo tpl_form_field_image('sharepic', $activity['sharepic']);}
                        <div class="help-block">*建议图片像素：100*100</div>
                    </div>
                </div>


            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-12">
                <input name="submit" type="submit" value="提交" class="btn btn-primary col-lg-1" />
                <input type="hidden" name="token" value="<?php echo ($_W['token']); ?>" />
            </div>
        </div>


    </form>
</div>

<script type="text/javascript">
    function check(form) {

        if (!form['title'].value) {
            $("input[name='title']").focus();
            alert('主人，请输入活动的主题名称');
            return false;
        }
        if (!form['headtitle'].value) {
            $("input[name='headtitle']").focus();
            alert('主人，请输入网页标题');
            return false;
        }
        if (!form['activitytitle'].value) {
            $("input[name='activitytitle']").focus();
            alert('主人，请输入活动的主题内容');
            return false;
        }
        if (!form['undertaker'].value) {
            $("input[name='undertaker']").focus();
            alert('主人，请输入主办方名称');
            return false;
        }

        if (!form['begintime'].value) {
            $("input[name='begintime']").focus();
            alert('主人，请点击选择活动的开始日期');
            return false;
        }
        if (!form['endtime'].value) {
            $("input[name='endtime']").focus();
            alert('主人，请点击选择活动的截止日期');
            return false;
        }

        var str1 = $('#cal1').val();
        var str2 = $('#cal2').val();
        var d1 = new Date(str1);
        var d2 = new Date(str2);
        if(Date.parse(d1) - Date.parse(d2) >= 0){
            $("input[name='endtime']").focus();
            alert('主人，截止日期要比开始日期晚一些日子');
            return false;
        }

        if (!form['place'].value) {
            $("input[name='place']").focus();
            alert('主人，请输入兑奖地址');
            return false;
        }
        if (!form['tel'].value) {
            $("input[name='tel']").focus();
            alert('主人，请输入兑奖电话');
            return false;
        }else{
            var tel = $('#tel').val();
            if (tel.search(/^(13[0-9]|15[0|3|6|7|8|9]|18[8|9])\d{8}$/) == -1) {
                $("input[name='tel']").focus();
                //alert('主人，请输入正确的手机号码');
                return true;
            }
        }

        if ((!form['ad1'].value && form['ad1content'].value.length > 0) || (form['ad1'].value && form['ad1content'].value.length <= 0)) {
            $("input[name='ad1']").focus();
            alert('请输入广告一区的标题和内容');
            return false;
        }
        if ((!form['ad2'].value && form['ad2content'].value.length > 0) || (form['ad2'].value && form['ad2content'].value.length <= 0)) {
            $("input[name='ad2']").focus();
            alert('请输入广告二区的标题和内容');
            return false;
        }
        if ((!form['ad3'].value && form['ad3content'].value.length > 0) || (form['ad3'].value && form['ad3content'].value.length <= 0)) {
            $("input[name='ad3']").focus();
            alert('请输入广告三区的标题和内容');
            return false;
        }
        return true;
    }
</script>

{elseif $operation == 'display'}
<ul class="unstyled activity_list">
    {loop $list $row}
    <li>
        <a href="{php echo $this->CreateWebUrl('activity', array('activityId' => $row['id'], 'op' => 'post'))}" class="activity_pic">{if $row['thumb']}<img src="<?php echo ($_W['attachurl']); echo ($row['thumb']); ?>" width="180" />{else}<img src="{php echo $_W['siteroot'].$this->geturl(1);}" width="180" />{/if}</a>
        <div class="activity_main">
            <p>
                <span class="pull-left"><?php echo ($row['title']); ?></span><span class="pull-right"><a href="{php echo $this->CreateWebUrl('activity', array('activityId' => $row['id'], 'op' => 'post'))}">编辑</a>
				<a href="#" onclick="javascript:jConfirm('确定删除？',function(){location.href='{php echo $this->CreateWebUrl('activity', array('activityId' => $row['id'], 'op' => 'delete'))}';},'消息');">删除</a></span>
            </p>
        </div>
    </li>
    {/loop}
</ul>
{/if}